#pragma once
#include <iostream>
#include <memory>

using namespace std;

//抽象主题角色AbstractPermission
class AbstractPermission{
public:
	virtual void modifyUserInfo() = 0;
	virtual void viewNote() = 0;
	virtual void publishNote() = 0;
	virtual void modifyNote() = 0;
	virtual void setLevel(int level) = 0;
}; 

//真实主题角色RealPermission
class RealPermission : public AbstractPermission{
public:
	void modifyUserInfo(){
		cout << "修改用户信息!" << endl;
	}
	
	void viewNote(){
		cout << "查看帖子!" << endl;
	}
	
	void publishNote(){
		cout << "发布新帖!" << endl;
	}
	
	void modifyNote(){
		cout << "修改帖子!" << endl;
	}
	
	void setLevel(int level){
		
	}
};


//代理主题角色PermissionProxy
class PermissionProxy : public AbstractPermission{
public:
	PermissionProxy(){
		permission = make_shared<RealPermission>();
		level = 0;
	}
	
	void modifyUserInfo(){
		if(level == 0){
			cout << "对不起,你没有权限!" << endl;
		}else if(level == 1){
			permission->modifyUserInfo();
		}
	}
	
	void viewNote(){
		cout << "查看帖子!" << endl;
	}
	
	void publishNote(){
		if(level == 0){
			cout << "对不起,你没有权限!" << endl;
		}else if(level == 1){
			permission->publishNote();
		}
	}
	
	void modifyNote(){
		if(level == 0){
			cout << "对不起,你没有权限!" << endl;
		}else if(level == 1){
			permission->modifyNote();
		}
	}
	
	void setLevel(int level){
		this->level = level;
	}
private:
	shared_ptr<RealPermission> permission;
	int level;
};